package com.cs.study.homework._0311.TestTCP3;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(4567);
        //2. 通过accept建立连接, 得到socket对象
        Socket socket = serverSocket.accept();
        //3. 从socket中得到输入输出流
        InputStream in = socket.getInputStream();
        FileOutputStream out = new FileOutputStream("E://a//copy.txt");

        //4. 利用输入输出流进行读写操作
        byte[] bytes = new byte[1024];
        int readCount;
        while ((readCount = in.read())!=-1){
            out.write(bytes,0,readCount);
        }


        out.flush();
        in.close();
        socket.close();
    }
}
